#include "bmemallocatorss.h"

void *BMemAllocatorSS::allocator(size_t size)
{
    size_t AllocNodeSize = sizeof(AllocType);
    AllocType *p;
    if (!headofFreeList)
    {
        headofFreeList = p = reinterpret_cast<AllocType*>(new char[size * chunkSize]);
        for (int i = 0; i < chunkSize - 1; ++i)
        {
            p->next = (AllocType*)((char*)p + size);
            p = p->next;
        }
        p->next = nullptr;
    }
    p = headofFreeList;
    headofFreeList = headofFreeList->next;
    return p;
}

void BMemAllocatorSS::deallocator(void *ptr)
{
    AllocType* p = static_cast<AllocType*>(ptr);
    p->next = headofFreeList;
    headofFreeList = p;
}
